Repository navigation
chore(spanner): enforce read-only mode on DML statements with RETURNING - #15073
Open
sakthivelmanii wants to merge 2 commits into
Open
sakthivelmanii wants to merge 2 commits into
sakthivelmanii wants to merge 2 commits into
Conversation
Reject DML statements (`INSERT`, `UPDATE`, `DELETE`) containing a GoogleSQL `THEN RETURN` or PostgreSQL `RETURNING` clause when a Cloud Spanner `Connection` is in read-only mode or inside a `READ_ONLY_TRANSACTION`, as well as on read-only single-use transactions. Previously, executing a DML statement with a returning clause through `Connection.execute`, `Connection.executeAsync`, or a read-only single-use transaction bypassed the read-only check enforced by `Connection.executeQuery`: - In autocommit read-only mode, the statement opened a read-write transaction and committed the mutation. - In transactional read-only mode, `Connection.execute` and `Connection.executeAsync` threw `IllegalArgumentException` instead of `SpannerException` with `ErrorCode.FAILED_PRECONDITION`. All query-returning execution paths now consistently reject DML returning statements in read-only contexts with `SpannerException` (`ErrorCode.FAILED_PRECONDITION`) before starting a transaction or consuming any statement tag.
Contributor
There was a problem hiding this comment.
Code Review
This pull request refactors and centralizes the validation of DML statements with returning clauses in read-only connections and single-use transactions, ensuring checks are performed before allocating a unit of work or marking a transaction as used. Comprehensive tests are added to verify these behaviors. Feedback is provided to customize the error message in checkDmlReturningAllowed for plain DML statements without a returning clause to avoid misleading errors.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reject DML statements (
INSERT,UPDATE,DELETE) containing a GoogleSQLTHEN RETURNor PostgreSQLRETURNINGclause when a Cloud SpannerConnectionis in read-only mode or inside aREAD_ONLY_TRANSACTION, as well as on read-only single-use transactions.Previously, executing a DML statement with a returning clause through
Connection.execute,Connection.executeAsync, or a read-only single-use transaction bypassed the read-only check enforced byConnection.executeQuery:Connection.executeandConnection.executeAsyncthrewIllegalArgumentExceptioninstead ofSpannerExceptionwithErrorCode.FAILED_PRECONDITION.All query-returning execution paths now consistently reject DML returning statements in read-only contexts with
SpannerException(ErrorCode.FAILED_PRECONDITION) before starting a transaction or consuming any statement tag.